<template>
  <div id="SmoothedLineChart"
       :style="{height: height, width: width}"></div>
</template>

<script>
import echarts from "echarts";

export default {
  name: "SmoothedLineChart",
  props: {
    xData: {
      type: Array,
      required: true
    },
    seriesData: {
      type: Array,
      required: true
    },
    title: {
      type: String,
      default: ''
    },
    width: {
      type: String,
      default: '400px'
    },
    height: {
      type: String,
      default: '400px'
    },
  },
  mounted() {
    this.graph = echarts.init(document.getElementById('SmoothedLineChart'))
    this.graph.clear()
    this.graph.setOption(this.option)
  },
  watch: {
    seriesData() {
      this.graph.clear()
      this.graph.setOption(this.option)
    }
  },
  data() {
    return {
      graph: null,
      option: {
        title: {
          text: this.title
        },
        tooltip: {
          trigger: 'axis'
        },
        grid: {
          left: '3%',
          right: '50px',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          name: '题库名',
          data: this.xData    // 如：['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value',
          name: '单位(%)'
        },
        series: [
          {
            data: this.seriesData,    // 如：[820, 932, 901, 934, 1290, 1330, 1320]
            type: 'line',
            smooth: true,
            animationDuration: 2800,
            animationEasing: "cubicInOut"
          }
        ]
      }
    }
  }
}
</script>

<style scoped>
</style>